﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IService.DataDLL.Utility;
using IService.DataDLL;
using System.Data;
using IService.Business;
using IService.Utility;

namespace IService.User_center
{
    public partial class MySupplyPurchaseList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //try
            //{
                if (!base.IsPostBack)
                {
                    this.BindData();
                }
            //}
            //catch (Exception er)
            //{ 
              
            //}
        }

        public void BindData()
        {
            PagingEntity pe = new PagingEntity("SupplyPurchase", "RequestType,Type,CreateDate  desc");
            pe.PageSize = Pagination.PageSize;
            pe.PageIndex = Pagination.PageIndex;
            pe.WhereClause = "UserID = " + SessionState.CurrentUser.ID;

            DataTable table = DTVBusiness.SupplyPurchaseManager.GetSupplyPurchaseListPagin(pe);
            this.rptNewsList.DataSource = table;
            this.rptNewsList.DataBind();
            this.Pagination.BindName = "BindData";
            this.Pagination.Count = pe.RecordCount;
            this.Pagination.BindPager();
        }
       
        protected string GetShortDetail(string detail)
        {
            if (detail.Length > 15)
            {
                return StringUtil.GetShortContent(detail, 15) + "...";
            }
            else
            {
                return detail;
            }
        }

        //获取需求分类
        public string GetSupplyPurchaseType(int requestType, int type)
        {
            string result = "";

            switch (requestType)
            {
                case 1:
                    if (type == 1)
                        result = "产品采购";
                    else
                        result = "产品供应";
                    break;
                case 2:
                    if (type == 1)
                        result = "技术求购";
                    else
                        result = "技术转让";
                    break;
                case 3:
                    if (type == 1)
                        result = "股权投资";
                    else
                        result = "股权转让";
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }
        
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DeleteSupplyPurchaseByLink(object sender, EventArgs e)
        {
            string Id = ((LinkButton)sender).CommandArgument.ToString();
            bool hassuccess = DTVBusiness.SupplyPurchaseManager.DeleteSupplyPurchase(int.Parse(Id));
            if (hassuccess)
            {
                this.BindData();
                JsUtil.Alert("删除成功！", this.Page);
            }
            else
            {
                JsUtil.Alert("删除失败！", this.Page);
            }
        }
    }
}